package com.xcity.game.battle.res;

import com.alibaba.fastjson.annotation.JSONField;
import com.xcity.db.entity.Player;
import com.xcity.game.battle.pve.template.ResStageTemplate;

import naga.x.App;
import naga.x.game.template.TemplateService;
import naga.x.game.time.TimeUpdater;

/**
 * 资源副本
 * @author shipeng.zhu
 */
public class ResStage implements Comparable<ResStage>{
	@JSONField(name = "0")
	protected int id;
	@JSONField(name = "1")
	protected long passTime;

	@JSONField(serialize = false)
	protected ResStageTemplate template;
	@JSONField(serialize = false)
	protected int index;
//	@JSONField(serialize = false)
//	protected int subIndex;
	
	public ResStage(){}
	
	public ResStage(ResStageTemplate template){
		this.id = template.getId();
		this.template = template;
	}
	//---serialize start
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public long getPassTime() {
		return passTime;
	}
	public void setPassTime(long passTime) {
		this.passTime = passTime;
	}
	//---serialize end

	@JSONField(serialize = false)
	public boolean isPass(){
		return passTime > 0;
	}
	
	@JSONField(serialize = false)
	public ResStageTemplate getTemplate() {
		return template != null? template : (template = App.getApp().getServiceManager().get(TemplateService.class).get(ResStageTemplate.class, id));
	}
	@JSONField(serialize = false)
	public int getIndex() {
		return index;
	}
	@JSONField(serialize = false)
	public void setIndex(int index) {
		this.index = index;
	}
//	@JSONField(serialize = false)
//	public int getSubIndex() {
//		return subIndex;
//	}
//	@JSONField(serialize = false)
//	public void setSubIndex(int subIndex) {
//		this.subIndex = subIndex;
//	}

	public void end(long endTime){
		if(passTime == 0){
			passTime = endTime;
		}
	}

	@Override
	public int compareTo(ResStage o) {
		return getId() - o.getId();
	}
}
